<?php
require_once "opsdbconn.php";

$flag=0;


//全部
$sql = "SELECT CONCAT(0 + sum(amount)) as value from o_order WHERE id in(SELECT oo.id FROM o_order oo LEFT JOIN o_order_list ool ON ool.order_id = oo.id WHERE ( oo.STATUS = 7 OR oo.`status` = 2 OR oo.`status` = 3 OR oo.`status` = 4 OR oo.`status` = 5) and oo.shop_name <>'诚美家具旗舰店' GROUP BY ool.order_id )";


$query=$mysqli->query($sql);
$res=mysqli_fetch_array($query);



//今天
$sql1 = "select sum(amount)  as value from o_order where date_format(pay_time,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d')  and  ( status=7 or `status`=2 or `status`=3 or `status`=4 or `status`=5 ) and shop_name <>'诚美家具旗舰店'";


$query1=$mysqli->query($sql1);
$res1=mysqli_fetch_array($query1);

//昨天
$sql2 = "select sum(amount)  as value from o_order where  date_format(pay_time,'%Y-%m-%d')= date_format(date_sub(now(),interval 1 day),'%Y-%m-%d')  and  ( status=7 or  `status`=2 or `status`=3 or `status`=4 or `status`=5 ) and shop_name <>'诚美家具旗舰店'";

$query2=$mysqli->query($sql2);
$res2=mysqli_fetch_array($query2);



$jsonStr["all"] = number_format($res['value'],2);
$jsonStr["today"] = number_format($res1['value'],2);
$jsonStr["yesterday"] = number_format($res2['value'],2);
 



//全部
$sqljd = "SELECT CONCAT(0 + sum(amount)) as value from o_order WHERE id in(SELECT oo.id FROM o_order oo LEFT JOIN o_order_list ool ON ool.order_id = oo.id WHERE ( oo.STATUS = 7 OR oo.`status` = 2 OR oo.`status` = 3 OR oo.`status` = 4 OR oo.`status` = 5) AND ool.goods_id != 35 and oo.source_platform='京东' and date_format(oo.pay_time,'%Y-%m')=date_format(now(),'%Y-%m')  GROUP BY ool.order_id )";



$queryjd=$mysqli->query($sqljd);
$resjd=mysqli_fetch_array($queryjd);

//京东统计
$jsonStr["jd"]=number_format($resjd['value'],2);


//全部
$sqltb = "SELECT CONCAT(0 + sum(amount)) as value from o_order WHERE id in(SELECT oo.id FROM o_order oo LEFT JOIN o_order_list ool ON ool.order_id = oo.id WHERE ( oo.STATUS = 7 OR oo.`status` = 2 OR oo.`status` = 3 OR oo.`status` = 4 OR oo.`status` = 5) AND ool.goods_id != 35 and oo.source_platform='淘宝' and date_format(oo.pay_time,'%Y-%m')=date_format(now(),'%Y-%m') and oo.shop_name <>'诚美家具旗舰店' GROUP BY ool.order_id )";

$querytb=$mysqli->query($sqltb);
$restb=mysqli_fetch_array($querytb);



//淘宝统计
$jsonStr["tb"]=number_format($restb['value'],2);

$allvalue=$restb['value']+$resjd['value'];


//京东统计
$jsonStr["jdbfb"]=number_format(($resjd['value']/$allvalue)*100,2);
//京东统计
$jsonStr["tbbfb"]=number_format(($restb['value']/$allvalue)*100,2);


//刷单金额
$jsonStr["sdje"]=0;

$sqltk = "SELECT CONCAT(0 + sum(amount)) as value from o_order WHERE id in(SELECT oo.id FROM o_order oo LEFT JOIN o_order_list ool ON ool.order_id = oo.id WHERE oo.status=8 GROUP BY ool.order_id )";

$querytk=$mysqli->query($sqltk);
$restk=mysqli_fetch_array($querytk);
//退款金额
$jsonStr["tkje"]=number_format($restk['value'],2);


$sqltoptkje="SELECT * from (SELECT shop_name,pay_time,sum(amount) as am from o_order where to_days(pay_time) = to_days(now()) and shop_name <>'诚美家具旗舰店' and  `status`=8 GROUP BY shop_name) as p ";

$querytkj=$mysqli->query($sqltoptkje);
$t=array();
while($arr3 = mysqli_fetch_assoc($querytkj)){

if($arr3['shop_name']=="新印科技礼品旗舰店"){
	$t['1']=number_format($arr3['am'],2);
}
if($arr3['shop_name']=="中顺文印礼品定制专营店"){
	$t['2']=number_format($arr3['am'],2);
}
if($arr3['shop_name']=="台大文印"){
	$t['3']=number_format($arr3['am'],2);
}
if($arr3['shop_name']=="禄佳文印"){
	$t['4']=number_format($arr3['am'],2);
}

if($arr3['shop_name']=="晶富文印"){
	$t['5']=number_format($arr3['am'],2);
}

if($arr3['shop_name']=="万千印品"){
	$t['6']=number_format($arr3['am'],2);
}

if($arr3['shop_name']=="新印科技工厂店"){
	$t['7']=number_format($arr3['am'],2);
}

if($arr3['shop_name']=="shineage耗材工厂店"){
	$t['8']=number_format($arr3['am'],2);
}
if($arr3['shop_name']=="真迹耗材工厂店"){
	$t['9']=number_format($arr3['am'],2);
}
if($arr3['shop_name']=="永利字画"){
	$t['10']=number_format($arr3['am'],2);
}
if($arr3['shop_name']=="新印科技办公用品企业店"){
	$t['11']=number_format($arr3['am'],2);
}
if($arr3['shop_name']=="馨印办公旗舰店"){
	$t['12']=number_format($arr3['am'],2);
}


}












$sqltop11="SELECT * from (SELECT shop_name,pay_time,sum(amount) as am from o_order where to_days(pay_time) = to_days(now()) and shop_name <>'诚美家具旗舰店' and ( status=7 or  `status`=2 or `status`=3 or `status`=4 or `status`=5 ) GROUP BY shop_name) as p ";

$querytop11=$mysqli->query($sqltop11);

$p=array();

while($arr2 = mysqli_fetch_assoc($querytop11)){
if($arr2['shop_name']=="新印科技礼品旗舰店"){
	$p['1']=number_format($arr2['am'],2);
}
if($arr2['shop_name']=="中顺文印礼品定制专营店"){
	$p['2']=number_format($arr2['am'],2);
}
if($arr2['shop_name']=="台大文印"){
	$p['3']=number_format($arr2['am'],2);
}
if($arr2['shop_name']=="禄佳文印"){
	$p['4']=number_format($arr2['am'],2);
}

if($arr2['shop_name']=="晶富文印"){
	$p['5']=number_format($arr2['am'],2);
}

if($arr2['shop_name']=="万千印品"){
	$p['6']=number_format($arr2['am'],2);
}

if($arr2['shop_name']=="新印科技工厂店"){
	$p['7']=number_format($arr2['am'],2);
}

if($arr2['shop_name']=="shineage耗材工厂店"){
	$p['8']=number_format($arr2['am'],2);
}
if($arr2['shop_name']=="真迹耗材工厂店"){
	$p['9']=number_format($arr2['am'],2);
}
if($arr2['shop_name']=="永利字画"){
	$p['10']=number_format($arr2['am'],2);
}
if($arr2['shop_name']=="新印科技办公用品企业店"){
	$p['11']=number_format($arr2['am'],2);
}
if($arr2['shop_name']=="馨印办公旗舰店"){
	$p['12']=number_format($arr2['am'],2);
}

	

}




$sqltop10="SELECT * from (SELECT shop_name,pay_time,count(1) as sl,sum(amount) as am from o_order where date_format(pay_time,'%Y-%m')=date_format(now(),'%Y-%m') and shop_name <>'诚美家具旗舰店' and ( status=7 or  `status`=2 or `status`=3 or `status`=4 or `status`=5 ) GROUP BY shop_name) as p ORDER BY p.sl desc limit 10";
$querytop10=$mysqli->query($sqltop10);



$i=1;
while($arr = mysqli_fetch_assoc($querytop10)){
	# code...
$jsonStr['shoplist'][$i]['name']=$arr['shop_name'];
$jsonStr['shoplist'][$i]['ddsl']=number_format($arr['sl'],0);
$jsonStr['shoplist'][$i]['sdje']=0;
$jsonStr['shoplist'][$i]['tkje']=0;
$jsonStr['shoplist'][$i]['xsmb']=number_format(100000,2);


$jsonStr['shoplist'][$i]['jrxse']=0;

$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/100000)*100,0);

if($arr['shop_name']=="新印科技礼品旗舰店"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(50000,2);


	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/50000)*100,0);

if(isset($t['1'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['1'];
}


if(isset($p['1'])){

	$jsonStr['shoplist'][$i]['jrxse']=$p['1'];
}
}
if($arr['shop_name']=="中顺文印礼品定制专营店"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(25000,2);
	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/25000)*100,0);

if(isset($t['2'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['2'];
}

if(isset($p['2'])){
	$jsonStr['shoplist'][$i]['jrxse']=$p['2'];


}
}
if($arr['shop_name']=="台大文印"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(90000,2);
	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/90000)*100,0);

	if(isset($t['3'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['3'];
}

	if(isset($p['3'])){
	$jsonStr['shoplist'][$i]['jrxse']=$p['3'];
}
}
if($arr['shop_name']=="禄佳文印"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(100000,2);
	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/100000)*100,0);

	if(isset($t['4'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['4'];
}
	if(isset($p['4'])){
	$jsonStr['shoplist'][$i]['jrxse']=$p['4'];
}

}

if($arr['shop_name']=="晶富文印"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(45000,2);
	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/45000)*100,0);

	if(isset($t['5'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['5'];
}
	if(isset($p['5'])){
		$jsonStr['shoplist'][$i]['jrxse']=$p['5'];
	}
	
		
}

if($arr['shop_name']=="万千印品"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(200000,2);
	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/200000)*100,0);

	if(isset($t['6'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['6'];
}
	if(isset($p['6'])){
	$jsonStr['shoplist'][$i]['jrxse']=$p['6'];
}
}

if($arr['shop_name']=="新印科技工厂店"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(200000,2);
	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/200000)*100,0);

	if(isset($t['7'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['7'];
}
	if(isset($p['7'])){
	$jsonStr['shoplist'][$i]['jrxse']=$p['7'];
}
}

if($arr['shop_name']=="shineage耗材工厂店"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(10000,2);
	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/10000)*100,0);
	if(isset($t['8'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['8'];
}
	if(isset($p['8'])){
	$jsonStr['shoplist'][$i]['jrxse']=$p['8'];
}
}
if($arr['shop_name']=="真迹耗材工厂店"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(20000,2);
	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/20000)*100,0);

	if(isset($t['9'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['9'];
}
	if(isset($p['9'])){
	$jsonStr['shoplist'][$i]['jrxse']=$p['9'];
}
}
if($arr['shop_name']=="永利字画"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(90000,2);
	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/90000)*100,0);

	if(isset($t['10'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['10'];
}
	 if(isset($p['10'])){
	$jsonStr['shoplist'][$i]['jrxse']=$p['10'];
}
}
if($arr['shop_name']=="新印科技办公用品企业店"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(90000,2);
	$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/90000)*100,0);

	if(isset($t['11'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['11'];
}
	if(isset($p['11'])){
	$jsonStr['shoplist'][$i]['jrxse']=$p['11'];
}
}
if($arr['shop_name']=="馨印办公旗舰店"){
	$jsonStr['shoplist'][$i]['xsmb']=number_format(90000,2);
		$jsonStr['shoplist'][$i]['jdt']=number_format(($arr['am']/90000)*100,0);

		if(isset($t['12'])){

	$jsonStr['shoplist'][$i]['tkje']=$t['12'];
}
	if(isset($p['12'])){
	$jsonStr['shoplist'][$i]['jrxse']=$p['12'];
}
}



$jsonStr['shoplist'][$i]['dqxse']=number_format($arr['am'],2);


 
$i=$i+1;

}



mysqli_close($mysqli); 

echo jsonSuccess($jsonStr);

?>